<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>json</title>
</head>
<body>
    <script>
    // var jsonStr = '{"a": "Hello", "b": "world"}'
    // var obj = JSON.parse(jsonStr)//json对象转换为字符串对象
    // console.log(obj)

    var obj2 = { a: 'hello', b: 'world', c: false }
    var str = JSON.stringify(obj2)//字符对象转换为json对象
    console.log(str)
    console.log(typeof str)
    var xhr = new XMLHttpRequest()
    xhr.open('GET', 'http://www.liulongbin.top:3006/api/getbooks')
    xhr.send()
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        console.log(xhr.responseText)//获取的对象为json形式的字符串
        console.log(typeof xhr.responseText)//string

        var result = JSON.parse(xhr.responseText)
        console.log(result)
      }
    }

    </script>
</body>
</html>